﻿Imports PhDir.Repository
Imports PhDir.DAL

Public Class Main

    Public ReadOnly DepartmentRepository As DepartmentRepository
    Public ReadOnly PhoneRepository      As PhoneRepository
    Public ReadOnly UserRepository       As UserRepository

    Private Shared mainInstance As Main

    Private Sub New()
        'Me.SetupPhoneDb()

        Me.DepartmentRepository = New DepartmentRepository()
        Me.PhoneRepository = New PhoneRepository()
        Me.UserRepository = New UserRepository()
    End Sub

    ''' <summary>
    ''' Create PhoneDb if PhoneDb does not exist.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SetupPhoneDb()
        Dim actualResult As Object = Nothing

        Using dbConnection = New DbConnection(DbContext.PhoneContext)
            SetupDb.InitializeDatabase()
        End Using
    End Sub

    Public Shared ReadOnly Property Instance As Main
        Get
            If (mainInstance Is Nothing) Then
                mainInstance = New Main()
            End If

            Return mainInstance
        End Get
    End Property

End Class